package com.deyuanyun.pic.pbf.controller.dto.defect.repair;

import com.deyuanyun.pic.common.spring.SpringAppliction;
import com.deyuanyun.pic.common.util.ObjectUtil;
import com.deyuanyun.pic.common.util.format.DateFormat;
import com.deyuanyun.pic.common.util.format.NumberFormat;
import com.deyuanyun.pic.pbf.domain.RepairPipeWeld;
import com.deyuanyun.pic.pbf.domain.RepairPipeWelding;
import com.deyuanyun.pic.pbf.service.RepairPipeWeldService;
import com.deyuanyun.pic.settings.support.biz.CodeUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * 焊接表
 */
public class RepairPipeWeldingVO extends RepairDto {

    /**
     * 焊接-wps编号(自定义编号)
     */
    private String wpsNumber;

    /**
     * 焊接-无损检测类型
     */
    private String ndtType;

    /**
     * 焊接-是否返修：0，否；1，是
     */
    private String repairind;

    /**
     * 焊接-检测单位
     */
    private String testingCompany;

    /**
     * 焊接-检测日期
     */
    private String testDate;

    /**
     * 检测报告
     */
    private String testPresentation;

    /**
     * 焊接材质
     */
    private String weldingMaterial;

    /**
     * 焊缝信息
     */
    List<RepairPipeWeldVO> weldList;

    /**
     * 是否完成该节点任务：0，没有完成；1，已经完成
     */
    private Short isCompletion;

    public RepairPipeWeldingVO(Short isCompletion) {
        this.isCompletion = isCompletion;
    }

    public Short getIsCompletion() {
        return isCompletion;
    }

    public void setIsCompletion(Short isCompletion) {
        this.isCompletion = isCompletion;
    }

    public String getWpsNumber() {
        return wpsNumber;
    }

    public void setWpsNumber(String wpsNumber) {
        this.wpsNumber = wpsNumber;
    }

    public String getNdtType() {
        return ndtType;
    }

    public void setNdtType(String ndtType) {
        this.ndtType = ndtType;
    }

    public String getRepairind() {
        return repairind;
    }

    public void setRepairind(String repairind) {
        this.repairind = repairind;
    }

    public String getTestingCompany() {
        return testingCompany;
    }

    public void setTestingCompany(String testingCompany) {
        this.testingCompany = testingCompany;
    }

    public String getTestDate() {
        return testDate;
    }

    public void setTestDate(String testDate) {
        this.testDate = testDate;
    }

    public String getTestPresentation() {
        return testPresentation;
    }

    public void setTestPresentation(String testPresentation) {
        this.testPresentation = testPresentation;
    }

    public String getWeldingMaterial() {
        return weldingMaterial;
    }

    public void setWeldingMaterial(String weldingMaterial) {
        this.weldingMaterial = weldingMaterial;
    }

    public List<RepairPipeWeldVO> getWeldList() {
        return weldList;
    }

    public void setWeldList(List<RepairPipeWeldVO> weldList) {
        this.weldList = weldList;
    }

    public void fromDomain(RepairPipeWelding domain) {

        if (ObjectUtil.isEmptyAll(domain)) {
            return;
        }

        // 赋值
        this.fromDomain(domain.getId(), domain.getCreateRemark());

        // 焊接-wps编号(自定义编号)
        this.wpsNumber = domain.getWpsNumber();
        // 焊接-无损检测类型
        this.ndtType = CodeUtil.getName(domain.getNdtType());
        // 焊接-是否返修：0，否；1，是
        this.repairind = "1".equals(domain.getRepairind()) ? "是" : "否";
        // 焊接-检测单位
        this.testingCompany = domain.getTestingCompany();
        // 焊接-检测日期
        this.testDate = DateFormat.format(domain.getTestDate());
        // 焊接材质
        this.weldingMaterial = domain.getWeldingMaterial();

        RepairPipeWeldService repairPipeWeldService = SpringAppliction.getBean(RepairPipeWeldService.class);
        // 通过“焊接信息编号”查询焊缝信息
        List<RepairPipeWeld> repairPipeWeldList = repairPipeWeldService.queryRepairPipeWeldList(domain.getId());
        // 焊缝信息
        List<RepairPipeWeldVO> welds = new ArrayList<RepairPipeWeldVO>();
        for (RepairPipeWeld repairPipeWeld : repairPipeWeldList) {
            RepairPipeWeldVO repairPipeWeldDto = new RepairPipeWeldVO();
            repairPipeWeldDto.setGwwNumber(repairPipeWeld.getGwwNumber());
            repairPipeWeldDto.setX(NumberFormat.format(repairPipeWeld.getX()));
            repairPipeWeldDto.setY(NumberFormat.format(repairPipeWeld.getY()));
            repairPipeWeldDto.setZ(NumberFormat.format(repairPipeWeld.getZ()));
            welds.add(repairPipeWeldDto);
        }
        this.weldList = welds;
    }

    /**
     * 换管--焊缝对象
     */
    class RepairPipeWeldVO {

        // 环焊缝编号
        private String gwwNumber;
        // 位置x
        private String x;
        // 位置y
        private String y;
        // 位置z
        private String z;

        public String getGwwNumber() {
            return gwwNumber;
        }

        public void setGwwNumber(String gwwNumber) {
            this.gwwNumber = gwwNumber;
        }

        public String getX() {
            return x;
        }

        public void setX(String x) {
            this.x = x;
        }

        public String getY() {
            return y;
        }

        public void setY(String y) {
            this.y = y;
        }

        public String getZ() {
            return z;
        }

        public void setZ(String z) {
            this.z = z;
        }
    }
}
